package com.common.manager;


import com.common.viewmodel.BaseViewModel;

import java.util.HashMap;
import java.util.Map;

/**
 * @类名: ViewModelListenerManager
 * @描述: 视图模式监听管理者
 * @作者 cms
 * @创建日期 2017/3/7 17:27
 */
public class ViewModelListenerManager {


    private static final String TAG = "ViewModelListenerManager";

    //监听视图模式
    private Map<Class<? extends BaseViewModel.ViewModelListener>, BaseViewModel.ViewModelListener> viewModelListenerHashMap = new HashMap<>();

    private static class LazyHolder {
        private static final ViewModelListenerManager INSTANCE = new ViewModelListenerManager();
    }

    private ViewModelListenerManager() {
    }

    public static ViewModelListenerManager instance() {
        return LazyHolder.INSTANCE;
    }

    public void register(BaseViewModel.ViewModelListener viewModelListener) {
        if (!viewModelListenerHashMap.containsKey(viewModelListener.getClass())) {
            viewModelListenerHashMap.put(viewModelListener.getClass(), viewModelListener);
        }
    }

    public void unRegister(BaseViewModel.ViewModelListener viewModelListener) {
        if (viewModelListenerHashMap.containsKey(viewModelListener.getClass())) {
            viewModelListenerHashMap.remove(viewModelListener.getClass());
        }
    }

    public Map<Class<? extends BaseViewModel.ViewModelListener>, BaseViewModel.ViewModelListener> getViewModelListenerHashMap() {
        return viewModelListenerHashMap;
    }

    public void setViewModelListenerHashMap(Map<Class<? extends BaseViewModel.ViewModelListener>, BaseViewModel.ViewModelListener> viewModelListenerHashMap) {
        this.viewModelListenerHashMap = viewModelListenerHashMap;
    }
}
